package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.CityWideAllCircleBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 15.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class SameAgeAllCircleAdapter  extends  RecyclerView.Adapter<SameAgeAllCircleAdapter.ViewHolder> implements View.OnClickListener {
    private static final String TAG = "SameAgeAllCircleAdapter";
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<CityWideAllCircleBean.DataBean> databean =new ArrayList<>();
    private Context mcontent;
    public SameAgeAllCircleAdapter(List<CityWideAllCircleBean.DataBean> bean, Context content) {
        databean.addAll(bean);
        mcontent = content;

    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_popular_circle_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
         Glide.with(mcontent).load(RBConstants.SERVER_URL+"/Public/Uploads/"+databean.get(position).url).into(holder.iv_hangzhou_circle);
       // Log.e(TAG,"CityWideAllCircleAdapter===============>"+ RBConstants.SERVER_URL+"/Public/Uploads/"+databean.get(position).url);
        int state = databean.get(position).state;
        if(state  == 0){
            holder.tv_join.setText("关注");
        }else if(state  == 1){
            holder.tv_join.setText("已关注");
        }

         holder.tv_circle_class.setText(databean.get(position).cat_name);
       holder.tv_circle_introduce.setText(databean.get(position).intro);



    }
    @Override
    public int getItemCount() {
        return databean.size();
    }

    @Override
    public void onClick(View view) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(view);
        }
    }
    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_join;
        private TextView tv_circle_introduce;
        private TextView tv_circle_class;
        private ImageView iv_hangzhou_circle;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_join = (TextView) itemView.findViewById(R.id.item_popular_circle_recyclerview_tv_join);
            tv_circle_introduce = (TextView) itemView.findViewById(R.id.item_popular_circle_recyclerview_tv_circle_introduce);
            tv_circle_class = (TextView) itemView.findViewById(R.id.item_popular_circle_recyclerview_tv_circle_class);
            iv_hangzhou_circle = (ImageView) itemView.findViewById(R.id.item_popular_circle_recyclerview_iv_hangzhou_circle);
        }
    }
}

